<script>

export default {
  name: 'VipExam',
  data () {
    return {
      show: false,
      formData: {
        idcard: '',
        idcard1: '',
        idcard2: '',
        userinfoId: '',
        userinfoStatus: 3,
        examContent: ''
      },
      idcard1Url: '',
      idcard2Url: '',
      basePath: '',
      type: ''
    }
  },
  methods: {
    init (type, id) {
      this.show = true
      this.type = type
      if (id) {
        this.$axios.get(`vip/exam/info/${id}`).then(data => {
          this.formData = { ...data }
          this.idcard1Url = this.basePath + data.idcard1
          this.idcard2Url = this.basePath + data.idcard2
        })
      }
    },
    submit (userinfoStatus) {
      this.formData.userinfoStatus = userinfoStatus
      if (!this.formData.examContent) {
        if (userinfoStatus === 3) {
          this.formData.examContent = '通过'
        } else {
          this.formData.examContent = '拒绝'
        }
      }
      this.$axios.post('vip/exam', this.formData).then(() => {
        this.$message.success('审核完成！')
        this.show = false
        this.$emit('close')
      }).catch(e => e)
    }
  },
  created () {
    this.basePath = process.env.VUE_APP_BASE_PATH
    this.uploadUrl = this.basePath + 'upload'
  }
}
</script>

<template>
<el-dialog title="实名审核" :visible.sync="show">
  <el-form :model="formData" label-width="100px">
    <el-form-item label="身份证号" prop="idcard">
      <el-input v-model="formData.idcard" disabled/>
    </el-form-item>
    <el-form-item label="身份证正面" prop="idcard1">
      <el-upload
        disabled
        class="avatar-uploader"
        :show-file-list="false">
        <img v-if="idcard1Url" :src="idcard1Url" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item label="身份证反面" prop="idcard2">
      <el-upload
        disabled
        class="avatar-uploader"
        :show-file-list="false">
        <img v-if="idcard2Url" :src="idcard2Url" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item label="审核意见">
      <el-input type="textarea" v-model="formData.examContent" :disabled="type === 'view'" :rows="5" maxlength="120" show-word-limit placeholder="审核意见，可以为空"/>
    </el-form-item>
    <el-form-item v-if="type === 'exam'">
      <el-button type="success" @click="submit(3)">通过</el-button>
      <el-button type="warning" @click="submit(4)">拒绝</el-button>
    </el-form-item>
    <el-form-item v-else label="审核状态">
      <el-tag v-if="formData.userinfoStatus === 3" type="success">通过</el-tag>
      <el-tag v-if="formData.userinfoStatus === 4" type="warning">拒绝</el-tag>
    </el-form-item>
  </el-form>
</el-dialog>
</template>

<style scoped lang="scss">

</style>
